import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import Login from "../views/Login.vue";
import Regist from "../views/Regist.vue";
Vue.use(VueRouter);
/**
 * 重写路由的push方法，消除跳转到相同路径时候的报错
 */
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error);
};
const routes = [
  {
    path: "/regist",
    name: "Regist",
    component: Regist
  },
  {
    path: "/login",
    name: "Login",
    component: Login
  },
  {
    path: "/main",
    name: "Main",
    component: () => import("../views/Main/Main.vue"),
    children: [
      {
        path: "home",
        name: "Home",
        component: Home
      },
      {
        path: "about",
        name: "about",
        component: () =>
          import(/* webpackChunkName: "about" */ "@/views/Main/About.vue")
      },
      {
        path: "config",
        name: "Config",
        component: () => import("../views/Main/Config.vue")
      },
      {
        path: "application",
        name: "Application",
        component: () => import("../views/Main/Application.vue")
      },
      {
        path: "mytable",
        name: "MyTable",
        component: () => import("../views/Main/ContentDisplay/MyTable.vue")
      },
      {
        path: "formTable",
        name: "FormTable",
        component: () => import("../views/Main/ContentDisplay/FormTable.vue")
      },
      {
        path: "carousel",
        name: "Carousel",
        component: () => import("../views/Main/ContentDisplay/Carousel.vue")
      },
      {
        path: "bar",
        name: "Bar",
        component: () => import("../views/Main/echarts/Bar.vue")
      },
      {
        path: "pie",
        name: "Pie",
        component: () => import("../views/Main/echarts/Pie.vue")
      }
    ]
  }
];

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes
});

export default router;
